package com.itic.hpp.spu;

import com.itic.appbase.framework.Base.BaseCode;
import com.itic.appbase.framework.utils.ValueHelper;
import com.itic.mobile.base.BaseMobile;
import com.itic.system.delivery.method.persistence.model.DeliveryMethod;
import com.itic.system.spu.category.persistence.model.SpuCategory;
import com.itic.system.spu.category.service.SpuCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/hpp/spu/category")
public class SpuCategoryInterface extends BaseMobile {

    @Autowired
    private SpuCategoryService spuCategoryService;
    private static String[] ignoreProperties = new String[] { "createUser", "isEffective", "updateTime",
            "orgCode" };

    /**
     * 获取商品属性类型
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/list")
    @ResponseBody
    public Map<String,Object> list(HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        try{
            List<SpuCategory> spuCategories = this.spuCategoryService.findSpuCategory();
            List<Map<String, Object>> resultList = new ArrayList<>();
            resultList = ValueHelper.tranList2MapList(spuCategories, ignoreProperties);
            resultMap.put(BaseCode.DATA,resultList);
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }catch(Exception e){
            resultMap.put(BaseCode.CODE,BaseCode.SERVER_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SERVER_ERROR_MSG);
            logException("DeliveryInterface", "list", e.toString(),"发布类型接口",e);
        }
        isCrrossDomain(response);
        return resultMap;
    }
}
